package gv.project 
{
	import com.greensock.TweenMax;

	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;

	/**
	 * @author rick
	 */
	public class PlantIcon extends MovieClip
	{
		public var textBox : TextField;
		public var dot : Sprite;
		public var color : uint = 0x00FF00;
		public var ratioX : Number = 0;
		public var ratioY : Number = 0;

		public function PlantIcon()
		{
			addEventListener(Event.ADDED_TO_STAGE, onStageAdd);			
		}
		
		public function setState(i : int) : void
		{
			//trace("switching to state "+ i);
			switch(i)
			{
				case 0:
					TweenMax.to(dot, .5, {colorTransform:{tint:0x000000, tintAmount:0}});
				break;
				case 1:
					TweenMax.to(dot, .5, {colorTransform:{tint:0x0000ff, tintAmount:1}});
				break;
				case 2:
					TweenMax.to(dot, .5, {colorTransform:{tint:0xff0000, tintAmount:1}});
				break;
			}
		}

		private function onStageAdd(event : Event) : void
		{
			removeEventListener(Event.ADDED_TO_STAGE, onStageAdd);
			init();
		}

		public function init() : void
		{
			dot = new Sprite();
			addChild(dot);			
			dot.graphics.beginFill(color);
			dot.graphics.drawCircle(0, 0, 5);
			dot.graphics.endFill();
			addChild(textBox);
		}
		
		public function setName(name : String) : void
		{
			textBox = new TextField();
			textBox.width = 1;
			textBox.x = 0;
			textBox.y = 10;	
			textBox.autoSize = TextFieldAutoSize.CENTER;
			textBox.text = name;
		}
	}
}
